﻿using System;
using System.Collections.Generic;
using System.Text;
using ExtBusiness.Controls;

namespace ExtBusiness.Controls
{
    public class CreatPageChange
    {
        /// <summary>
        /// 创建翻页按钮
        /// </summary>
        /// <param name="mypage"></param>
        /// <param name="pagenow"></param>
        /// <param name="pageCount"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public StringBuilder CreatPageChanges(Pager mypage, int pagenow, int pageCount, int pagesize)
        {
            StringBuilder strPageHTML = new StringBuilder();
            string HeadShow = "";
            string FootShow = "";
            string GoPage = "转到第<select name='jumpPage' id='jumpPage' onchange='tosubmit()'>";
            if (pagenow == 1)
            {
                HeadShow = " 首页 上一页 ";
            }
            else
            {
                HeadShow = string.Format("<a href=\"javascript:tosubmit('1');\">首页</a> <a href=\"javascript:tosubmit('{0}');\">上一页</a> ", pagenow - 1);
            }
            if (pagenow == pageCount || pageCount == 0)
            {
                FootShow = " 下一页 尾页 ";
            }
            else
            {
                FootShow = string.Format("<a href=\"javascript:tosubmit('{0}');\">下一页</a> <a href=\"javascript:tosubmit('{1}');\">尾页</a> ", pagenow + 1, pageCount);
            }
            if (pageCount > 0)
            {
                for (int i = 1; i < pageCount + 1; i++)
                {
                    if (i == pagenow)
                    {

                        GoPage += string.Format("<option selected='selected' value='{0}'>{0}</option>", i);
                    }
                    else
                    {
                        GoPage += string.Format("<option value='{0}'>{0}</option>", i);
                    }
                }
            }
            GoPage += "</select>页";

            strPageHTML.Append(" <table width='100%' border='0' cellspacing='0' cellpadding='4'>");
            strPageHTML.AppendFormat("<tr><td style=\"text-align: right; height: 20px\">每页{0}行 共{1}行 当前{2}页 共{3}页 {4}{5}{6}</td></tr>",
                pagesize, mypage.RecordCount, pagenow, pageCount, HeadShow, FootShow, GoPage);

            return strPageHTML;

        }
    }
}
